﻿Imports System.Data.SqlClient
Partial Class login
    Inherits System.Web.UI.Page

    Protected Sub btnSignUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSignUp.Click
        Response.Redirect("registration.aspx")
    End Sub

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Try
            Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
            Dim str As String = "select count(*) from users where username='" + txtUserName.Text.ToLower() + "' and password = '" + txtPassword.Text + "'"
            Dim cmd As New SqlCommand(str, cn)
            cn.Open()
            If cmd.ExecuteScalar = 1 Then
                cn.Close()
                cn.Open()
                cmd = New SqlCommand("select banned from users where username='" + txtUserName.Text.ToLower() + "'", cn)
                If (cmd.ExecuteScalar = "allowed") Then
                    Session("username") = txtUserName.Text.ToLower
                    If (txtUserName.Text.ToLower = "admin") Then
                        Response.Redirect("welcome admin.aspx")
                    End If
                    Response.Redirect("default.aspx")

                Else
                    Label2.Text = "You are banned from our site."

                End If
            Else
                Label2.Text = "You have entered either wrong username or password."

            End If
        Catch ex As Exception
            Label2.Text = "Sorry for Inconvience ! Try after some time." + ex.Message
        End Try
    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect("forgotten password 1.aspx")
    End Sub

    Protected Sub txtPassword_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged

    End Sub
End Class
